package org.apache.jsp.procesa;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.io.*;
import java.util.*;
import beans.BeanLugares;
import mapping.LugarInteres;
import mapping.ElementoMapa;

public final class proc_005fbusquedalugaresfavs_005fuser_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.AnnotationProcessor _jsp_annotationprocessor;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
  }

  public void _jspDestroy() {
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html; charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			"../error/errorpage.jsp", true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write('\n');
      out.write('\n');
      out.write('\n');
      beans.BeanLugares mybean = null;
      synchronized (_jspx_page_context) {
        mybean = (beans.BeanLugares) _jspx_page_context.getAttribute("mybean", PageContext.PAGE_SCOPE);
        if (mybean == null){
          mybean = new beans.BeanLugares();
          _jspx_page_context.setAttribute("mybean", mybean, PageContext.PAGE_SCOPE);
        }
      }
      out.write('\n');
 
	String archivo = request.getParameter("archivo");

      out.write("\n");
      out.write("<script>\n");
      out.write("\tinicializaLugaresInteres('");
      out.print(archivo);
      out.write("');\n");
      out.write("</script>\n");
		
		//Obtencion de cada uno de los parametros de la busqueda...
		
		//Numero de resultados de busqueda por pagina
		int resultadosporpagina = 10;
		//Vemos por cual tupla hemos de comenzar la busqueda
		int inicTupla = Integer.parseInt(request.getParameter("iniciotupla"));
		
		String [] tipoLugaresElegidos = request.getParameterValues("tipo");	
		String nombreLugarInput =request.getParameter("nomlugar");
		String id_usuario = request.getParameter("id_usuario");
		
		//Flag para saber si se desea buscar solo lugares de interes o lugares propios (creados por el usuario)
		String chkboxlugaresinteres = request.getParameter("chkboxlugaresinteres");
		String chkboxlugarespropios = request.getParameter("chkboxlugarespropios");
		mybean.conectar();
		List listLugares = null;
		// si seleccionamos lugares de interes y no los propios
		if(chkboxlugaresinteres != null && chkboxlugarespropios == null) 
			listLugares = mybean.getLugares(tipoLugaresElegidos, nombreLugarInput, resultadosporpagina, inicTupla, id_usuario, 1);
		// si seleccionamos propios y no los de interes
		else if(chkboxlugaresinteres == null && chkboxlugarespropios != null) 
			listLugares = mybean.getLugares(tipoLugaresElegidos, nombreLugarInput, resultadosporpagina, inicTupla, id_usuario, 2);
		// e.c.o.c. busca por todos (tanto interes como no)
		else
			listLugares = mybean.getLugares(tipoLugaresElegidos, nombreLugarInput, resultadosporpagina, inicTupla, id_usuario, 0);
		
		mybean.generaXMLLugares(archivo, listLugares, id_usuario);
		
		if(listLugares == null)
	       		out.println("<p><h1>ERROR</h1></p>");
		else if(!listLugares.isEmpty()){
      out.write("\n");
      out.write("\t\t<form name=\"formlistadolugares\" id=\"formlistadolugares\" method=\"get\" onsubmit=\"return false;\">\t\n");
      out.write("\t\t\t<input type=\"hidden\" id=\"id_usuario\" name=\"id_usuario\" value=\"");
      out.print(id_usuario);
      out.write("\"/>\n");
      out.write("\t\t\t<input type=\"hidden\" id=\"archivo\" name=\"archivo\" value=\"");
      out.print(archivo);
      out.write("\"/>\n");
      out.write("\t\t\t<table border=\"1\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">\n");
      out.write("\t\t\t<tbody id=\"cuerpoTablaLugares\">\n");
      out.write("\t        <tr class=\"trcabeclista\">\n");
      out.write("\t        \t<td class=\"tdchk\">&nbsp;</td>\n");
      out.write("\t            <td id=\"tdnomlugar\"><b>NOMBRE</b></td>\n");
      out.write("\t            <td id=\"tddesclugar\"><b>DESCRIPCI&Oacute;N</b></td>\n");
      out.write("\t            <td id=\"tdtipolugar\"><b>TIPO</b></td>\n");
      out.write("\t            <td class=\"tdbotoneslugaresuserfavs\">&nbsp;</td>\n");
      out.write("\t        </tr>\n");
      out.write("\t        ");

				int  i = 1;
				Iterator it2 = listLugares.iterator();
				while(it2.hasNext()) {
					LugarInteres li = (LugarInteres)it2.next();
					int id_lugar = li.getId_elem_mapa();
			
      out.write("\n");
      out.write("\t\t\t<tr class=\"listado\" id=\"fila");
      out.print(li.getId_elem_mapa());
      out.write("\" onmouseover=\"iluminaFila(this)\" onmouseout=\"oscureceFila(this)\" >\n");
      out.write("\t\t\t\t<td>\n");
      out.write("\t\t\t\t\t<input type=\"hidden\" id=\"id_lugar");
      out.print(id_lugar);
      out.write("\" value=\"");
      out.print(id_lugar);
      out.write("\">\n");
      out.write("\t\t       \t\t<input type=\"checkbox\" class=\"chkboxes\" name=\"chkbx_lugares\"\n");
      out.write("\t\t       \t\t\t\tvalue = \"");
      out.print(id_lugar);
      out.write("\" onclick=\"habilitarBotones(this); habilitarAgregarTodo();\"/>\n");
      out.write("       \t\t\t</td>\t\n");
      out.write("\t\t\t\t<td class=\"nombrefav\">\n");
      out.write("\t\t\t\t\t<div>\n");
      out.write("\t\t\t\t\t\t");
      out.print(li.getNombre());
      out.write("\n");
      out.write("\t\t\t\t\t\t<a href=\"#celdaDivMapa\">\n");
      out.write("\t\t\t\t\t\t\t<span onclick = \"centraMapaEnLugar('fila");
      out.print(li.getId_elem_mapa());
      out.write("', 'coord");
      out.print(li.getId_elem_mapa());
      out.write("')\">\n");
      out.write("\t\t\t\t\t\t\t&raquo;\n");
      out.write("\t\t\t\t\t\t\t</span>\n");
      out.write("\t\t\t\t\t\t</a>\n");
      out.write("\t\t\t\t\t</div>\n");
      out.write("\t\t\t\t\t<input name=\"coordenadas\" id = \"coord");
      out.print(id_lugar);
      out.write("\" type=\"hidden\" value=\"");
      out.print(li.getLatitud());
      out.write(',');
      out.print(li.getLongitud());
      out.write("\"/>\t\t\n");
      out.write("\t\t\t\t</td>\n");
      out.write("\t\t\t\t<td class=\"descfav\">\n");
      out.write("\t\t       \t");

		       		final int MAX_LONG_DESCR = 80; 
			       	String desc = li.getDescripcion();
			        if(desc == null || desc.length()==0)
			             desc = "&nbsp;"; 
			        if(desc.length()>MAX_LONG_DESCR){
			            desc = desc.substring(0, MAX_LONG_DESCR + 1); 
			           	desc += "...";
			         }
		         
      out.write("       \n");
      out.write("\t\t         ");
      out.print(desc);
      out.write("\n");
      out.write("\t\t        </td>\n");
      out.write("\t\t       \t<td class=\"tipofav\">");
      out.print(li.getTipo_elem_mapa());
      out.write("</td>\n");
      out.write("\t\t       \t");
 /*String infoDetalleLugar = li.getNombre()+","+li.getDireccion()
			       		+","+li.getDescripcion()+","+li.getTipo_elem_mapa()
			       		+","+li.getLatitud()+","
			       		+li.getLongitud();*/
		        
      out.write("\t\t \n");
      out.write("\t       \t\t<td class = \"tdbotoneslugaresuserfavs\">\n");
      out.write("\t\t       \t\t<div>\t\t\n");
      out.write("\t\t\t       \t\t<button class=\"btnimg\" id=\"detallelugar ");
      out.print(li.getId_elem_mapa());
      out.write("\" title=\"Ver detalles\" onclick=\"verDetallesLugar(");
      out.print(li.getId_elem_mapa());
      out.write(")\">\n");
      out.write("\t\t\t\t\t\t  <img src=\"images/web/search.png\" alt=\"Ver +\"/>\n");
      out.write("\t\t\t\t\t\t</button>\n");
      out.write("\t\t\t\t\t\t");
 if(!li.getImagenesURL().isEmpty()) { 
      out.write("\n");
      out.write("\t\t\t\t\t\t\t<button class=\"btnimg\" id=\"fotoslugar ");
      out.print(li.getId_elem_mapa());
      out.write("\" title=\"Ver galer&iacute;a de fotos\" onclick=\"cargaGaleria(");
      out.print(li.getId_elem_mapa());
      out.write(")\">\n");
      out.write("\t\t\t\t\t\t\t\t<img src=\"images/web/galeria.png\" alt=\"Ver +\"/>\n");
      out.write("\t\t\t\t\t\t\t</button>\n");
      out.write("\t\t\t\t\t\t");
} else { 
      out.write("\n");
      out.write("\t\t\t\t\t\t\t<button class=\"btnimg\" disabled=\"disabled\"><img src=\"images/web/galeriadis.png\" alt=\"Ver +\"/></button>\n");
      out.write("\t\t\t\t\t\t");
 } 
      out.write("\t\n");
      out.write("\t\t\t\t\t\t<button class=\"btnimg\" id=\"btborr");
      out.print(id_lugar);
      out.write("\" onclick=\"borrarLugarFavorito()\" disabled=\"disabled\">\n");
      out.write("\t\t\t\t       \t  <img id=\"imgbtborr");
      out.print(id_lugar);
      out.write("\" src=\"images/web/borradis.png\" alt=\"Borrar\"/>\n");
      out.write("\t\t\t       \t\t</button>\n");
      out.write("\t\t\t\t\t\t");
 if(!li.isEs_de_interes()){
      out.write("\n");
      out.write("\t\t\t\t\t   \t<a href=\"mislugaresfavoritos.jsp#modlugarform\" \t\n");
      out.write("\t\t\t\t\t      <button class=\"btnimg\" id=\"btedit");
      out.print(id_lugar);
      out.write("\" disabled=\"disabled\" onclick=\"direccionar('modificalugarfavorito.jsp?id_lugar=");
      out.print(id_lugar);
      out.write("&id_usuario=");
      out.print(id_usuario);
      out.write("&archivo=");
      out.print(archivo);
      out.write("')\">\n");
      out.write("\t\t\t\t\t      \t<img id=\"imgbtedit");
      out.print(id_lugar);
      out.write("\" src=\"images/web/editdis.png\" alt=\"Editar\" border=\"0\"/>\n");
      out.write("\t\t\t\t\t      </button>\n");
      out.write("\t\t\t\t\t    </a>\n");
      out.write("\t\t\t\t\t ");
} 
      out.write("\n");
      out.write("\t\t       \t\t</div>\n");
      out.write("\t       \t\t</td>\n");
      out.write("\t\t     </tr>\n");
      out.write("\t\t     ");

		      i++;
		      }//fin while
		
      out.write("\n");
      out.write("\t\t</tbody>\n");
      out.write("\t</table>\n");
      out.write("\t<div>\n");
      out.write("\t\t<button id=\"btselect\" class=\"mybtn\" onclick=\"selectAll('chkboxes')\">Seleccionar todo</button>\n");
      out.write("    \t<button id=\"btunselect\" class=\"mybtn\" onclick=\"deselectAll('chkboxes')\">Deseleccionar todo</button>\n");
      out.write("    </div>\n");
      out.write("   <br/>\n");
      out.write("    <div class=\"centrado\">\n");
      out.write("   \t ");
 if(inicTupla > 1){
		
      out.write("\n");
      out.write("    \t\t<button id=\"ant\" class=\"mybtn\" onclick=\"retrocedeCursorResultSet('lista_lugares','form_lugares','proc_busquedalugaresfavs_user.jsp','get',");
      out.print(resultadosporpagina);
      out.write(")\">Anterior</button>\n");
      out.write("    \t");

		} if(inicTupla+resultadosporpagina < mybean.contadorTuplas){
		
      out.write("\n");
      out.write("    \t\t<button id=\"sig\" class=\"mybtn\" onclick=\"adelantaCursorResultSet('lista_lugares','form_lugares','proc_busquedalugaresfavs_user.jsp','get',");
      out.print(resultadosporpagina);
      out.write(")\">Siguiente</button>\n");
      out.write("    \t");
}
      out.write("\n");
      out.write("    </div>\n");
      out.write("\t</form>\n");
      out.write("\n");
      out.write("   \n");
      out.write("\t");
 
	mybean.desconectar();
	} else {
      out.write("\n");
      out.write("\t\t<center><p>No se han encontrado resultados para su b&uacute;squeda</p></center>\n");
      out.write("\t");
}
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
